<!DOCTYPE html>
<html>
<head>
    <title>拥有的角色</title>
    <#include "/common/import.ftl" >
    <script>
        var userId = "${userId!''}";
        $(function () {
            $('#userRoleList').datagrid({
                title: '',
                iconCls: 'icon-save',
                rownumbers: true,
                nowrap: false,
                fitColumns: true,
                striped: true,
                collapsible: false,
                url: 'user-role!data.action?userId=' + userId,
                remoteSort: false,
                pagination: true,
                singleSelect: true,
                pageList: [10, 20, 50],
                idField: 'roleId',

                columns: [[
                    {
                        field: 'roleCname', title: '角色名称', width: 150, sortable: false,
                        formatter: function (value) {
                            return '<span style="color:red">' + value + '</span>';
                        }
                    },
                    {field: 'roleEname', title: '角色标识', width: 150, sortable: false},
                    {
                        field: 'roleRemark', title: '所属机构', width: 150, sortable: true,
                        formatter: function (value) {
                            if (value) {
                                return value;
                            } else {
                                return "- -";
                            }
                        }
                    },
                    {
                        field: 'createTime', title: '创建时间', width: 150, sortable: false,
                        formatter: function (value) {
                            return getSmpFormatDateByLong(value, true);
                        }
                    },
                    {
                        title: '操作', field: 'giveId', width: 100,
                        formatter: function (value, row) {
                            if (value) {
                                return '<img name="hasGiveCheck" src="${ctx}/js/easyui/themes/default/images/tree_dnd_yes.png"  ondblclick="giveRole(this);" />';
                            } else {
                                return '<img name="hasGiveCheck" src="${ctx}/js/easyui/themes/default/images/tree_dnd_no.png" ondblclick="giveRole(this);" />';
                                ;
                            }
                        }
                    }
                ]]
            });
        });

        function giveRole(chko) {
            var node = $('#userRoleList').datagrid('getSelected');
            var tmppic = "${ctx}/js/easyui/themes/default/images/tree_dnd_yes.png";
            var flag = "add";
            if (chko.src.indexOf("tree_dnd_yes.png") > 0) {
                flag = "del";
                tmppic = "${ctx}/js/easyui/themes/default/images/tree_dnd_no.png";
            }
            $.ajax({
                type: "post",
                url: "${ctx}/uct/core/role-to-user.action?flag=" + flag + "&roleEname=" + node.roleEname + "&roleId=" + node.roleId + "&userId=" + userId,
                success: function (data, textStatus) {
                    chko.src = tmppic;
                }
            });
        }

    </script>
</head>

<body>
<table id="userRoleList"></table>
</body>
</html>